import re

import requests

def change(word):
    word_data = {
        63270: '0', 63582: '1', 59804: '2', 59607: '3',
        59630: '4', 60636: '5', 63487: '6', 60306: '7',
        61948: '8', 59882: '9'
    }
    return ''.join(word_data.get(ord(c), c) for c in word)


url = 'https://piaofang.maoyan.com/dashboard-ajax/movie?orderType=0&uuid=19a3e283ee8c8-08d2415466c0e7-26061851-1bcab9-19a3e283ee8c8&timeStamp=1761979537182&User-Agent=TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzE0MS4wLjAuMCBTYWZhcmkvNTM3LjM2&index=636&channelId=40009&sVersion=2&signKey=1e5adb24f4d65e986971fa10f09566c5&WuKongReady=h5'

headers = {
    'cookie':'_lxsdk_cuid=19a3e283ee8c8-08d2415466c0e7-26061851-1bcab9-19a3e283ee8c8; _lxsdk=19a3e283ee8c8-08d2415466c0e7-26061851-1bcab9-19a3e283ee8c8; _lx_utm=utm_source%3DBaidu%26utm_medium%3Dorganic; _lxsdk_s=19a3e283ee8-99a-35a-40b%7C%7C5',
    'host':'piaofang.maoyan.com',
    'referer':'https://piaofang.maoyan.com/dashboard/movie?movieid=1499659',
    'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36'
}

response = requests.get(url=url, headers=headers)
# print(response.status_code)
json_data = response.json()
# print(response.json())

# 解析加密字体
fontStyle = json_data['fontStyle']
# print(fontStyle)
# exit()
font_url = 'https:' + re.findall('url\("(.*?)"\)', fontStyle)[-1]
# print(font_url)
# exit()
font_content = requests.get(url=font_url).content
with open('static/font/font.woff', 'wb') as f:
    f.write(font_content)
movielist = json_data['movieList']['list']
for movie in movielist:
    # print(movie)


    dit = {
        '电影名' : movie['movieInfo']['movieName'],
        '上映时间' : movie['movieInfo']['releaseInfo'].replace('上映','') if movie['movieInfo']['releaseInfo'] != '' else '未上映',
        '总票房' : change(movie['sumBoxDesc']),
    }

    print(dit)




